<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ page import="com.wzu.pojo.Category" %>
<%@ page import="com.wzu.service.CategoryService" %>
<%@ page import="com.wzu.service.CategoryServiceImpl" %>
<%@ page import="java.util.List" %>
<!DOCTYPE html>
<html lang="zh-CN">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>添加图书</title>
    <style>
        input[type="submit"],.button-link {
            width: 100%;
            padding: 10px;
            border: none;
            border-radius: 4px;
            background-color: #4CAF50;
            color: white;
            cursor: pointer;
            text-decoration: none;
            display: inline-block;
            text-align: center;
        }

        input[type="submit"]:hover,.button-link:hover {
            background-color: #45a049;
        }

        .button-container {
            text-align: center;
            margin-top: 15px;
        }

        body, html {
            height: 100%;
            margin: 0;
            font-family: Arial, sans-serif;
        }

        .sidebar {
            width: 90px;
            background-color: #333;
            color: white;
            padding: 15px;
            position: fixed;
            top: 0;
            left: 0;
            height: 100%;
        }

        .sidebar h2 {
            padding: 10px;
            color: #fff;
        }

        .sidebar ul {
            list-style-type: none;
            padding: 0;
        }

        .sidebar ul li a {
            color: white;
            padding: 10px;
            display: block;
            text-decoration: none;
        }

        .sidebar ul li a:hover {
            background-color: #575757;
        }

        .sidebar ul li a.active {
            background-color: #4CAF50; /* 设置当前页面的背景颜色 */
        }

        .main-content {
            margin-left: 120px;
            padding: 20px;
        }

        .header {
            background-color: #333;
            color: white;
            text-align: center;
            padding: 10px 0;
        }

        .content {
            padding: 20px;
        }

        .form-container {
            background-color: #fff;
            padding: 20px;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
            width: 400px;
            margin: 0 auto;
        }

        .form-container h2 {
            text-align: center;
            margin-bottom: 20px;
        }

        .form-container label {
            display: block;
            margin-bottom: 5px;
        }

        .form-container input,.form-container select,.form-container textarea {
            width: 100%;
            padding: 8px;
            margin-bottom: 15px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
        }
    </style>
</head>
<body>
<div class="sidebar">
    <h2>菜单</h2>
    <ul>
        <li><a href="bookList.jsp" class="<%= request.getRequestURI().endsWith("bookList.jsp")? "active" : "" %>">图书列表</a></li>
        <li><a href="addBook.jsp" class="<%= request.getRequestURI().endsWith("addBook.jsp")? "active" : "" %>">添加图书</a></li>
        <li><a href="borrowRecord.jsp" class="<%= request.getRequestURI().endsWith("borrowRecord.jsp")? "active" : "" %>">借阅记录</a></li>
        <li><a href="readerList.jsp" class="<%= request.getRequestURI().endsWith("readerList.jsp")? "active" : "" %>">读者列表</a></li>
        <li id="adminLink" style="display: none;"><a href="../root/bookManagement.jsp" class="<%= request.getRequestURI().endsWith("bookManagement.jsp")? "active" : "" %>">管理入口</a></li>
        <li><a href="PersonalData.jsp" class="<%= request.getRequestURI().endsWith("PersonalData.jsp")? "active" : "" %>">个人中心</a></li>
        <li><a href="<%=request.getContextPath()%>/login.jsp">退出登录</a></li>
    </ul>
</div>
<div class="main-content">
    <div class="header">
        <a>图书信息管理系统 - 添加图书</a>
    </div>
    <div class="content">
        <div class="form-container">
            <h2>添加图书</h2>
            <form id="addBookForm" action="<%=request.getContextPath()%>/addBook" method="post">
                <label for="title">书名:</label>
                <input type="text" id="title" name="title" required placeholder="请输入书名"><br>
                <label for="author">作者:</label>
                <input type="text" id="author" name="author" required placeholder="请输入作者"><br>
                <label for="publisher">出版社:</label>
                <input type="text" id="publisher" name="publisher" placeholder="请输入出版社"><br>
                <label for="publication_year">出版年份:</label>
                <input type="number" id="publication_year" name="publication_year" placeholder="请输入出版年份"><br>
                <label for="isbn">ISBN:</label>
                <input type="text" id="isbn" name="isbn" required placeholder="请输入ISBN"><br>
                <label for="price">价格:</label>
                <input type="number" id="price" name="price" step="0.01" required placeholder="请输入价格"><br>
                <label for="description">描述:</label>
                <textarea id="description" name="description" placeholder="请输入图书描述"></textarea><br>
                <label for="category_id">分类ID:</label>
                <select id="category_id" name="category_id" required>
                    <%
                        CategoryService categoryService = new CategoryServiceImpl();
                        List<Category> categoryList = categoryService.getCategories();
                        for (Category category : categoryList) {
                    %>
                    <option value="<%= category.getCategory_id() %>"><%= category.getCategory_name() %></option>
                    <%
                        }
                    %>
                </select><br>
                <label for="stock_quantity">库存数量:</label>
                <input type="number" id="stock_quantity" name="stock_quantity" required placeholder="请输入库存数量"><br>
                <label for="available_quantity">可用数量:</label>
                <input type="number" id="available_quantity" name="available_quantity" required placeholder="请输入可用数量"><br>
                <input type="submit" value="添加图书">
            </form>
        </div>
    </div>
</div>
<script src="https://code.jquery.com/jquery-3.6.4.min.js"></script>
<script>
    $(document).ready(function () {
        // 读取信息
        let userInfo = sessionStorage.getItem('userInfo');
        userInfo = JSON.parse(userInfo);
        console.log(userInfo);

        // 根据 isroot 的值动态显示/隐藏 "管理入口"
        if (userInfo.isroot === 0) {
            document.getElementById('adminLink').style.display = 'none';
        } else {
            document.getElementById('adminLink').style.display = 'list-item';
        }
    });
</script>
</body>
</html>